// Copyright 2013 Square, Inc.
package org.assertj.ohos.api.widget;

import ohos.agp.components.ToggleButton;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

public class ToggleButtonAssert
    extends AbstractCompoundButtonAssert<ToggleButtonAssert, ToggleButton> {
  public ToggleButtonAssert(ToggleButton actual) {
    super(actual, ToggleButtonAssert.class);
  }

  public ToggleButtonAssert hasOnText(CharSequence text) {
    isNotNull();
    CharSequence actualText = actual.getStateOnText();
    assertThat(actualText) //
        .overridingErrorMessage("Expected 'on' text <%s> but was <%s>.", text, actualText) //
        .isEqualTo(text);
    return this;
  }

  public ToggleButtonAssert hasOnText(int resId) throws NotExistException, WrongTypeException, IOException {
    isNotNull();
    String text = actual.getContext().getResourceManager().getElement(resId).getString();
    return hasOnText(text);
  }

  public ToggleButtonAssert hasOffText(CharSequence text) {
    isNotNull();
    CharSequence actualText = actual.getStateOffText();
    assertThat(actualText) //
        .overridingErrorMessage("Expected 'off' text <%s> but was <%s>.", text, actualText) //
        .isEqualTo(text);
    return this;
  }

  public ToggleButtonAssert hasOffText(int resId) throws NotExistException, WrongTypeException, IOException {
    isNotNull();
    String text = actual.getContext().getResourceManager().getElement(resId).getString();
    return hasOffText(text);
  }
}
